import { useContext, createContext } from 'react'

//创建上下文
export const ReduceContext = createContext({})

//提供上下文
export function ReduceContextProvide({ value, children }) {
  return (
    <>
      <ReduceContext value={value}>{children}</ReduceContext>
    </>
  )
}

//使用上下文
export function useReduceContext() {
  const context = useContext(ReduceContext)
  if (Object.keys(context).length === 0) {
    throw new Error('useReduceContext must be used within a ReduceContextProvider')
  }
  return context
}
